package com.leihao.product.controller;

import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.product.domian.listRequest.ListRequest;
import com.leihao.product.domian.ProductStats;
import com.leihao.product.domian.listRequest.ProductStatsListRequest;
import com.leihao.product.domian.vo.ProductStatsVo;
import com.leihao.product.service.ProductStatsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productStats")
@Api(tags = "商品属性管理")
public class ProductStatsController {

    @Autowired
    private ProductStatsService productStatsService;

    /**
     * 查询所有商品属性
     * @param listRequest
     * @return
     */
    @GetMapping("/findList")
    @ApiOperation(value = "查询所有商品属性")
    public R<PageInfo<ProductStatsVo>> findList(@RequestBody @Validated ListRequest listRequest)
    {
        PageInfo<ProductStatsVo> firstList = productStatsService.findList(listRequest);
        return R.ok(firstList);
    }

    /**
     * 根据编号查询商品属性信息
     * @param productStatsId
     * @return
     */
    @GetMapping("/findById/{productStatsId}")
    @ApiOperation(value = "根据编号查询商品属性信息")
    public R<ProductStatsVo> findById(@PathVariable Integer productStatsId)
    {
        ProductStatsVo productStats = productStatsService.findById(productStatsId);
        return R.ok(productStats);
    }
    /**
     * 逻辑删除
     * @param productStatsId
     * @return
     */
    @DeleteMapping("/delete/{productStatsId}")
    @ApiOperation(value = "逻辑删除")
    @ApiImplicitParam(name = "productStatsId",value = "主键ID",required = true,dataType = "Integer")
    public R delete(@PathVariable Integer productStatsId)
    {
        productStatsService.delete(productStatsId);
        return R.ok(null,"删除成功");
    }
    /**
     * 修改商品属性
     * @param productStats
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改商品属性")
    public R update(@RequestBody ProductStats productStats)
    {
        productStatsService.update(productStats);
        return R.ok(null,"修改成功");
    }
    /**
     * 添加商品属性
     * @param productStats
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品属性")
    public R add(@RequestBody ProductStats productStats)
    {
        productStatsService.add(productStats);
        return R.ok(null,"添加成功");
    }

    /**
     * 根据商品分类查询对应的属性/参数
     * @param productStatsListRequest
     * @return
     */
    @PostMapping("/findByAttrIdList")
    @ApiOperation(value = "根据商品分类查询对应的属性/参数")
    public R findByAttrIdList(@Validated @RequestBody ProductStatsListRequest productStatsListRequest)
    {
        PageInfo<ProductStatsVo> byAttrIdList = productStatsService.findByAttrIdList(productStatsListRequest);
        return R.ok(byAttrIdList);
    }


    /**
     * 根据类型编号,查询对应属性/参数
     * @param productAttrId
     * @param type
     * @return
     */
    @GetMapping("/findByAttrIdStatsAll/{productAttrId}/{type}")
    @ApiOperation(value = "根据商品分类查询对应的属性")
    public R<List<ProductStatsVo>> findByAttrIdStatsAll(@PathVariable Integer productAttrId, @PathVariable Integer type)
    {
        List<ProductStatsVo> byAttrIdList = productStatsService.findByAttrIdStatsAll(productAttrId,type);
        return R.ok(byAttrIdList);
    }


}
